home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / mawk10.zip / SYMTYPE.H < prev    next >
C/C++ Source or Header  |  1991-10-05  |  5KB  |  195 lines

  1.  
  2. /********************************************
  3. symtype.h
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the AWK programming language.
  8.  
  9. Mawk is distributed without warranty under the terms of
  10. the GNU General Public License, version 2, 1991.
  11. ********************************************/
  12.  
  13. /*$Log:    symtype.h,v $
  14.  * Revision 3.4.1.1  91/09/14  17:24:24  brennan
  15.  * VERSION 1.0
  16.  * 
  17.  * Revision 3.4  91/08/13  06:52:14  brennan
  18.  * VERSION .9994
  19.  * 
  20.  * Revision 3.3  91/06/29  09:47:34  brennan
  21.  * Only track NR if needed
  22.  * 
  23.  * Revision 3.2  91/06/28  04:17:42  brennan
  24.  * VERSION 0.999
  25.  * 
  26.  * Revision 3.1  91/06/07  10:28:24  brennan
  27.  * VERSION 0.995
  28.  * 
  29.  * Revision 2.2  91/05/15  12:07:43  brennan
  30.  * dval hash table for arrays
  31.  * 
  32.  * Revision 2.1  91/04/08  08:24:14  brennan
  33.  * VERSION 0.97
  34.  * 
  35. */
  36.  
  37. /* types related to symbols are defined here */
  38.  
  39. #ifndef  SYMTYPE_H
  40. #define  SYMTYPE_H
  41.  
  42.  
  43. /* struct to hold info about builtins */
  44. typedef struct {
  45. char *name ;
  46. PF_CP  fp ;  /* ptr to function that does the builtin */
  47. unsigned char min_args, max_args ; 
  48. /* info for parser to check correct number of arguments */
  49. } BI_REC ;
  50.  
  51. /*---------------------------
  52.    structures and types for arrays
  53.  *--------------------------*/
  54.  
  55. /* array hash nodes */
  56.  
  57. /* string node */
  58. typedef  struct anode {
  59. struct anode *link ;
  60. STRING *sval ;
  61. CELL   *cp ;
  62. }  ANODE ;
  63.  
  64. /* double node */
  65. typedef struct d_anode {
  66. struct d_anode *dlink ;
  67. ANODE *ap ;
  68. double dval ;
  69. } D_ANODE ;
  70.  
  71. typedef struct array {
  72. ANODE *link ;
  73. D_ANODE *dlink ;
  74. } *ARRAY ;
  75.  
  76. #define  CREATE         1
  77. #define  NO_CREATE      0
  78.  
  79. /* note ARRAY is a ptr to a hash table */
  80.  
  81. CELL *PROTO(array_find, (ARRAY,CELL *, int) ) ;
  82. INST *PROTO(array_loop, (INST *, CELL *, CELL *) ) ;
  83. void PROTO(array_delete, (ARRAY, CELL *) ) ;
  84. CELL *PROTO(array_cat, (CELL *, int) ) ;
  85. void PROTO(array_free, (ARRAY) ) ;
  86.  
  87. #define new_ARRAY() (ARRAY)memset(zmalloc(A_HASH_PRIME *\
  88.                         sizeof(struct array)),\
  89.                         0 , SIZE_T(A_HASH_PRIME*sizeof(struct array)))
  90.  
  91. extern  ARRAY  Argv ;
  92.  
  93. /* for parsing  (i,j) in A  */
  94. typedef  struct {
  95. INST *start ;
  96. int cnt ;
  97. } ARG2_REC ;
  98.  
  99. /*------------------------
  100.   user defined functions
  101.   ------------------------*/
  102.  
  103. typedef  struct fblock {
  104. char *name ;
  105. INST *code  ;
  106. unsigned short nargs ;
  107. char *typev ;  /* array of size nargs holding types */
  108. } FBLOCK ;   /* function block */
  109.  
  110. void  PROTO(add_to_fdump_list, (FBLOCK *) ) ;
  111. void  PROTO( fdump, (void) ) ;
  112.  
  113. /*-------------------------
  114.   elements of the symbol table
  115.   -----------------------*/
  116.  
  117. #define  ST_NONE 0
  118. #define  ST_VAR   1
  119. #define  ST_KEYWORD   2
  120. #define  ST_BUILTIN 3 /* a pointer to a builtin record */
  121. #define  ST_ARRAY   4 /* a void * ptr to a hash table */
  122. #define  ST_FIELD   5  /* a cell ptr to a field */
  123. #define  ST_FUNCT   6
  124. #define  ST_LENGTH  7  /* length is special */
  125. #define  ST_NR      8  /* and so is NR */
  126. #define  ST_LOCAL_NONE  9
  127. #define  ST_LOCAL_VAR   10
  128. #define  ST_LOCAL_ARRAY 11
  129.  
  130. #define  is_local(stp)   ((stp)->type>=ST_LOCAL_NONE)
  131.  
  132. typedef  struct {
  133. char *name ;
  134. char type ;
  135. unsigned char offset ;  /* offset in stack frame for local vars */
  136. union {
  137. CELL *cp ;
  138. int  kw ;
  139. PF_CP fp ;
  140. BI_REC *bip ;
  141. ARRAY  array ; 
  142. FBLOCK  *fbp ;
  143. } stval ;
  144. }  SYMTAB ;
  145.  
  146.  
  147. /*****************************
  148.  structures for type checking function calls
  149.  ******************************/
  150.  
  151. typedef  struct ca_rec {
  152. struct ca_rec  *link ;
  153. short type ;
  154. short arg_num ;  /* position in callee's stack */
  155. /*---------  this data only set if we'll  need to patch -------*/
  156. /* happens if argument is an ID or type ST_NONE or ST_LOCAL_NONE */
  157.  
  158. int call_offset ;
  159. /* where the type is stored */
  160. SYMTAB  *sym_p ;  /* if type is ST_NONE  */
  161. char *type_p ;  /* if type  is ST_LOCAL_NONE */
  162. }  CA_REC  ; /* call argument record */
  163.  
  164. /* type field of CA_REC matches with ST_ types */
  165. #define   CA_EXPR       ST_LOCAL_VAR
  166. #define   CA_ARRAY      ST_LOCAL_ARRAY
  167.  
  168. typedef  struct fcall {
  169. struct fcall *link ;
  170. FBLOCK  *callee ;
  171. short   call_scope ;
  172. FBLOCK  *call ;  /* only used if call_scope == SCOPE_FUNCT  */
  173. INST    *call_start ; /* computed later as code may be moved */
  174. CA_REC  *arg_list ;
  175. short   arg_cnt_checked ;
  176. unsigned line_no ; /* for error messages */
  177. } FCALL_REC ;
  178.  
  179. extern  FCALL_REC  *resolve_list ;
  180.  
  181. void PROTO(resolve_fcalls, (void) ) ;
  182. void PROTO(check_fcall, (FBLOCK*,int,FBLOCK*,CA_REC*,unsigned) ) ;
  183.  
  184. /* hash.c */
  185. unsigned  PROTO( hash, (char *) ) ;
  186. SYMTAB *PROTO( insert, (char *) ) ;
  187. SYMTAB *PROTO( find, (char *) ) ;
  188. SYMTAB *PROTO( save_id, (char *) ) ;
  189. void    PROTO( restore_ids, (void) ) ;
  190.  
  191. /* error.c */
  192. void  PROTO(type_error, (SYMTAB *) ) ;
  193.  
  194. #endif  /* SYMTYPE_H */
  195.